﻿using Enuo.Dotnet.Api.Models;
using Enuo.Dotnet.Api.Service;
using Enuo.Dotnet.Core.Autowired;
using Enuo.Dotnet.Core.Model;
using Enuo.Dotnet.Service;
using IdentityModel;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Enuo.Dotnet.Api.Controllers
{
  [Produces("application/json")]
  [Route("api/authenticate")]
  public class AuthenticateController : Controller
  {
    [AutowiredProperty]
    private IAuthenticateService _authenservice { get; set; }

    //public AuthenticateController(IAuthenticateService service)
    //{
    //  this._authenservice = service;
    //}

    [HttpPost("login")]
    public ServcieResult<LoginResult> login(LoginVo user)
    {
      if (!_authenservice.IsAuthenticated(user))
      {
        return new ServcieResult<LoginResult>(500, "用户名或密码错误", null);
      }

      return new ServcieResult<LoginResult>(_authenservice.Authorization(user));
    }
  }
}
